<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div>123</div>
  <script>
    let arr = [1, 2, 3, 4, 5, 6]
    let arr1 = arr.map(item => {
      return item * item
    })
    console.log(arr1)
    // 自己封装map方法
    function selfMap(arr, cb) {
      let newarr = []
      for (let i = 0; i < arr.length; i++) {
        let res = cb(arr[i])
        newarr.push(res)
      }
      return newarr
    }
    const arr2 = selfMap(arr, (item) => {
      return item * item
    })
    console.log(arr2);
  </script>
</body>

</html>